import os
import platform
import sys
import numpy as np
import math


# 14 汇总降维
def drop_sum(input_file, compression_ratio, dimension_reduction):
    """

    :param input_file: 输入文件地址
    :param compression_ratio: 压缩比例
    :param dimension_reduction: 降维方式, 0: 均值, 1: 总和, 2: 最大, 3: 最小
    :return: 数组格式输出数据
    """

    dimension_reduction = int(dimension_reduction)
    compression_ratio = int(compression_ratio)
    with open(input_file) as file_obj:
        array = eval(file_obj.read())
        # 处理数据
        length = len(array)
        n = int(length / compression_ratio)
        # 拆成n段
        after = []
        for value in range(n):
            list_array = array[math.floor(value / n * length):math.floor((value + 1) / n * length)]
            list_part = list(list_array)
            # 对每一段分析
            # {0: '均值', 1: '总和', 2: '最大', 3: '最小'}
            if dimension_reduction == 0:
                after.append(np.mean(list_part))
            if dimension_reduction == 1:
                after.append(np.sum(list_part))
            if dimension_reduction == 2:
                after.append(np.max(list_part))
            if dimension_reduction == 3:
                after.append(np.min(list_part))

        return after


if __name__ == '__main__':
    print(drop_sum(sys.argv[1], sys.argv[2], sys.argv[3]))
